package servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import po.City;
import service.CityService;

/**
 * Create By IntelliJ IDEA
 *
 * @author: jsonor
 * @create-Time: 2017/10/17 8:37
 * @description: 用于显示所有数据
 */
@WebServlet(name = "display", urlPatterns = {"/display"})
public class DisplayServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    CityService service = new CityService();
    try {
      List<City> cities = service.finaAll();
      request.setAttribute("cities", cities);
      request.getRequestDispatcher("/display.jsp").forward(request, response);
    } catch (Exception e) {
      request.setAttribute("error", e);
      request.getRequestDispatcher("/error.jsp").forward(request, response);
    }
  }
}
